package cn.com.cifi.mars.util;

import cn.com.cifi.mars.bean.bo.StartAndEndTimeBO;
import cn.com.cifi.mars.bean.vo.returnPlan.ReturnPlanDetailMonthData;
import cn.com.cifi.mars.bean.vo.returnPlan.ReturnPlanDetailYearData;
import cn.com.cifi.mars.bean.vo.returnPlan.returnReport.ReturnReportVo;
import cn.com.cifi.mars.bean.vo.signPlan.signOverall.MonthSignVo;
import cn.com.cifi.mars.bean.vo.signPlan.signOverall.OverallSignPlanVo;
import cn.com.cifi.mars.bean.vo.signPlan.signOverall.YearSignVo;
import cn.com.cifi.mars.constant.Constants;
import cn.com.cifi.mars.constant.WhetherEnum;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * 类名称：OverallReturnPlanTemplate
 * 类描述：全盘回款计划模板
 * 创建人：jyx
 * 创建时间：2020年01月07日 上午11:20:00
 * @version 1.0.0
 */

@Slf4j
public class OverallReturnPlanTemplate {
    private static final String TEMPLATE_PATH = "/template/overall_return_template.xlsx";

    private XSSFWorkbook workbook;

    private XSSFSheet sheet;

    //默认sheet索引
    private int defaultSheetIndex = 0;
    //数据开始行
    private int dataBeginRow = 3;
    //当前行标
    private int currentDataRowCursor = dataBeginRow;
    //月份动态列模板开始索引
    private int dynamicColumnBeginIndex = 23;
    //当前列标
    private int currentDataColumnCursor = dynamicColumnBeginIndex;
    //单元格样式
    private XSSFCellStyle cellStyle;
    //表头单元格样式
    private XSSFCellStyle cellStyleZ;
    //汇总行文字单元格样式
    private XSSFCellStyle cellStyleA1;
    //汇总行权益比例单元格样式
    private XSSFCellStyle cellStyleA2;
    //汇总行数值单元格样式(数字-4位小数)
    private XSSFCellStyle cellStyleA3;
    //汇总行百分比单元格样式
    private XSSFCellStyle cellStyleA4;

    //数据行文字单元格样式
    private XSSFCellStyle cellStyleB1;
    //数据行权益比例单元格样式
    private XSSFCellStyle cellStyleB2;
    //数据行数值单元格样式(数字-4位小数)
    private XSSFCellStyle cellStyleB3;
    //数据行百分比单元格样式
    private XSSFCellStyle cellStyleB4;

    //权益比例
    private static final String EQUITY_RATIO  = "equityRatio";
    //数字-4位小数
    private static final String NUMERIC_FOUR = "numericByFout";
    //百分率
    private static final String ACHIEVING_RATE   = "achievingRate ";

    //文字单元格宽度
    private int columnWidthA;
    //百分比单元格宽度
    private int columnWidthB;
    //金额单元格宽度
    private int columnWidthC;

    public OverallReturnPlanTemplate(StartAndEndTimeBO startAndEndTimeBO, String name) {
        //开始时间
        LocalDateTime startDate = startAndEndTimeBO.getStartDate();
        //结束时间
        LocalDateTime endDate = startAndEndTimeBO.getEndDate();
        try {
            InputStream tempInputStream = OverallReturnPlanTemplate.class.getResourceAsStream(TEMPLATE_PATH);
            if (tempInputStream != null) {
                workbook = new XSSFWorkbook(tempInputStream);
                sheet = workbook.getSheetAt(defaultSheetIndex);
                setSheetDate(name);

                XSSFRow row = sheet.getRow(defaultSheetIndex);

                cellStyleZ = row.getCell(0).getCellStyle();
                cellStyleA1 = sheet.getRow(3).getCell(0).getCellStyle();
                cellStyleA2 = sheet.getRow(3).getCell(4).getCellStyle();
                cellStyleA3 = sheet.getRow(3).getCell(17).getCellStyle();
                cellStyleA4 = sheet.getRow(3).getCell(22).getCellStyle();
                cellStyleB1 = sheet.getRow(4).getCell(0).getCellStyle();
                cellStyleB2 = sheet.getRow(4).getCell(4).getCellStyle();
                cellStyleB3 = sheet.getRow(4).getCell(17).getCellStyle();
                cellStyleB4 = sheet.getRow(4).getCell(22).getCellStyle();

                columnWidthA = sheet.getColumnWidth(0);
                columnWidthB = sheet.getColumnWidth(4);
                columnWidthC = sheet.getColumnWidth(17);


                for (LocalDateTime time = startDate; LocalDateTimeUtils.compareDate(time, endDate,
                        1); time = LocalDateTimeUtils.addDate(time)) {
                    if(currentDataColumnCursor == 23){
                        XSSFCell cell = row.getCell(currentDataColumnCursor);
                        cell.setCellValue(time.getYear() + "年" + time.getMonthValue() + "月");
                        cell.setCellStyle(cellStyleZ);
                        currentDataColumnCursor+=16;
                    }else if (currentDataColumnCursor != 23){
                        //创建单元格
                        for (int i = 0; i < 16; i++) {
                            row.createCell(currentDataColumnCursor+i);
                        }
                        //合并单元格
                        sheet.addMergedRegion(new CellRangeAddress(0, 0, currentDataColumnCursor, currentDataColumnCursor+15));
                        XSSFCell cell = row.getCell(currentDataColumnCursor);
                        cell.setCellValue(time.getYear() + "年" + time.getMonthValue() + "月");
                        cell.setCellStyle(cellStyleZ);
                        //标题行-动态扩展
                        cellDynamicPropagation(currentDataColumnCursor,"month");
                        currentDataColumnCursor+=16;
                    }

                    if(time.getMonthValue()==12 || LocalDateTimeUtils.compareDate(time, endDate,2)){
                        //创建单元格
                        for (int i = 0; i < 15; i++) {
                            row.createCell(currentDataColumnCursor+i);
                        }
                        sheet.addMergedRegion(new CellRangeAddress(0, 0, currentDataColumnCursor,currentDataColumnCursor+13));
                        row.getCell(currentDataColumnCursor).setCellValue(time.getYear()+"年年度合计");
                        row.getCell(currentDataColumnCursor).setCellStyle(cellStyleZ);
                        cellDynamicPropagation(currentDataColumnCursor,"year");
                        currentDataColumnCursor+=14;
                    }

                }
            }
        } catch (Exception e) {
            log.error("行数：" + currentDataColumnCursor);
            log.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }

    /**
     * 单元格动态扩展
     * @param index 起始坐标
     * @param type 扩展类型(year:年，month:月)
     *
     */
    public void cellDynamicPropagation(int index,String type){
        XSSFRow rowOne = sheet.getRow(1);
        XSSFRow rowTwo = sheet.getRow(2);

        if(type.equals("month")){
            for (int i = 0; i < 16; i++) {
                XSSFCell cellOne = rowOne.createCell(index + i);
                XSSFCell cellTwo = rowTwo.createCell(index + i);
                cellOne.setCellStyle(cellStyleZ);
                cellTwo.setCellStyle(cellStyleZ);
            }

            //标题行1,单元格处理
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index, index));
            rowOne.getCell(index).setCellValue("期初应收账款\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index+1, index+1));
            rowOne.getCell(index+1).setCellValue("本期签约\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+2, index+3));
            rowOne.getCell(index+2).setCellValue("实际数");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+4, index+5));
            rowOne.getCell(index+4).setCellValue("测算数");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+6, index+7));
            rowOne.getCell(index+6).setCellValue("调整数");
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index+8, index+8));
            rowOne.getCell(index+8).setCellValue("已签未回回款数\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index+9, index+9));
            rowOne.getCell(index+9).setCellValue("期初应退回款数\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+10, index+13));
            rowOne.getCell(index+10).setCellValue("回款合计");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+14, index+15));
            rowOne.getCell(index+14).setCellValue("回款率");

            //标题行2,单元格处理
            rowTwo.getCell(index+2).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+3).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+4).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+5).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+6).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+7).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+10).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+11).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+12).setCellValue("回款合计\n" + "（万元）");
            rowTwo.getCell(index+13).setCellValue("期末应收账款\n" + "（万元）");
            rowTwo.getCell(index+14).setCellValue("累计签约回款率\n" + "（%）");
            rowTwo.getCell(index+15).setCellValue("年度签约回款率\n" + "（%）");

            sheet.setColumnWidth(index, columnWidthC);
            sheet.setColumnWidth(index+1, columnWidthC);
            sheet.setColumnWidth(index+2, columnWidthC);
            sheet.setColumnWidth(index+3, columnWidthC);
            sheet.setColumnWidth(index+4, columnWidthC);
            sheet.setColumnWidth(index+5, columnWidthC);
            sheet.setColumnWidth(index+6, columnWidthC);
            sheet.setColumnWidth(index+7, columnWidthC);
            sheet.setColumnWidth(index+8, columnWidthC);
            sheet.setColumnWidth(index+9, columnWidthC);
            sheet.setColumnWidth(index+10, columnWidthC);
            sheet.setColumnWidth(index+11, columnWidthC);
            sheet.setColumnWidth(index+12, columnWidthC);
            sheet.setColumnWidth(index+13, columnWidthC);
            sheet.setColumnWidth(index+14, columnWidthB);
            sheet.setColumnWidth(index+15, columnWidthB);

        }else if(type.equals("year")) {
            for (int i = 0; i < 14; i++) {
                XSSFCell cellOne = rowOne.createCell(index + i);
                XSSFCell cellTwo = rowTwo.createCell(index + i);
                cellOne.setCellStyle(cellStyleZ);
                cellTwo.setCellStyle(cellStyleZ);
            }

            //标题行1,单元格处理
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index, index));
            rowOne.getCell(index).setCellValue("年初应收账款\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index+1, index+1));
            rowOne.getCell(index+1).setCellValue("年度签约\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+2, index+3));
            rowOne.getCell(index+2).setCellValue("年度实际数");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+4, index+5));
            rowOne.getCell(index+4).setCellValue("年度测算数");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+6, index+7));
            rowOne.getCell(index+6).setCellValue("年度调整数");
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index+8, index+8));
            rowOne.getCell(index+8).setCellValue("年度已签未回回款数\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 2, index+9, index+9));
            rowOne.getCell(index+9).setCellValue("年初应退回款数\n" + "（万元）");
            sheet.addMergedRegion(new CellRangeAddress(1, 1, index+10, index+13));
            rowOne.getCell(index+10).setCellValue("年度回款合计");

            //标题行2,单元格处理
            rowTwo.getCell(index+2).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+3).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+4).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+5).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+6).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+7).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+10).setCellValue("增量回款\n" + "（万元）");
            rowTwo.getCell(index+11).setCellValue("存量回款\n" + "（万元）");
            rowTwo.getCell(index+12).setCellValue("回款合计\n" + "（万元）");
            rowTwo.getCell(index+13).setCellValue("年末应收账款\n" + "（万元）");

            sheet.setColumnWidth(index, columnWidthC);
            sheet.setColumnWidth(index+1, columnWidthC);
            sheet.setColumnWidth(index+2, columnWidthC);
            sheet.setColumnWidth(index+3, columnWidthC);
            sheet.setColumnWidth(index+4, columnWidthC);
            sheet.setColumnWidth(index+5, columnWidthC);
            sheet.setColumnWidth(index+6, columnWidthC);
            sheet.setColumnWidth(index+7, columnWidthC);
            sheet.setColumnWidth(index+8, columnWidthC);
            sheet.setColumnWidth(index+9, columnWidthC);
            sheet.setColumnWidth(index+10, columnWidthC);
            sheet.setColumnWidth(index+11, columnWidthC);
            sheet.setColumnWidth(index+12, columnWidthC);
            sheet.setColumnWidth(index+13, columnWidthC);
        }
    }


    public void setSheetDate(String name) {
        workbook.setSheetName(defaultSheetIndex, workbook.getSheetName(defaultSheetIndex).replace("回款计划", name));
    }

    /**
     * 批量插入行
     *
     * @param list 报表数据
     */
    public synchronized void appendRows(List<ReturnReportVo> list) {
        for (ReturnReportVo vo : list) {
            this.appendRow(vo);
        }

    }

    /**
     * 插入行
     *
     * @param
     */
    public synchronized void appendRow(ReturnReportVo vo) {
        XSSFRow row = sheet.getRow(currentDataRowCursor);
        if (row == null) {
            row = sheet.createRow(currentDataRowCursor);
        }
        row.setHeightInPoints(Constants.HEIGHT_POINTS);
        boolean isParentLevel;
        if(null == vo.getProductName()){
            isParentLevel = true;
        }else {
            isParentLevel = false;
        }

        int index = 0;
        //项目信息
        this.appendCell(row, index++,vo.getOrgBasicsVo().getProjectName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getOrgBasicsVo().getProjectCode(),isParentLevel,"");
        //分期信息
        this.appendCell(row, index++,vo.getOrgBasicsVo().getStageName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getOrgBasicsVo().getStageCode(),isParentLevel,"");
        this.appendCell(row, index++, vo.getOrgBasicsVo().getEquityRatio(),isParentLevel,EQUITY_RATIO);
        this.appendCell(row, index++,vo.getOrgBasicsVo().getOpmarketing(),isParentLevel,"");
        this.appendCell(row, index++,null == vo.getOrgBasicsVo().getIsAndTable() ? "" :  vo.getOrgBasicsVo().getIsAndTable() == 1?"是":"否",isParentLevel,"");
        this.appendCell(row, index++,null == vo.getOrgBasicsVo().getExistingHouses() ? "" : vo.getOrgBasicsVo().getExistingHouses() == 1?"现房销售":"非现房销售",isParentLevel,"");
        //组团信息
        this.appendCell(row, index++,vo.getGroupName(),isParentLevel,"");
        //产品信息
        this.appendCell(row, index++,vo.getProProductName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getProProductCode(),isParentLevel,"");
        this.appendCell(row, index++,vo.getProductName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getProductCode(),isParentLevel,"");
        this.appendCell(row, index++,vo.getBusinessTypeName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getFreeTypeName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getProTypeName(),isParentLevel,"");
        this.appendCell(row, index++,vo.getCarryOverTimeStr(),isParentLevel,"");

        //全盘签约与回款
        this.appendCell(row, index++,vo.getSignAndReturn().getTotalValue(),isParentLevel,NUMERIC_FOUR);
        this.appendCell(row, index++,vo.getSignAndReturn().getAccumulativeSold(),isParentLevel,NUMERIC_FOUR);
        this.appendCell(row, index++,vo.getSignAndReturn().getAccumulativeReturn(),isParentLevel,NUMERIC_FOUR);
        this.appendCell(row, index++,vo.getSignAndReturn().getSignNotReturn(),isParentLevel,NUMERIC_FOUR);
        this.appendCell(row, index++,vo.getSignAndReturn().getNotSignNotReturn(),isParentLevel,NUMERIC_FOUR);
        this.appendCell(row, index++,vo.getSignAndReturn().getSignReturnRate(),isParentLevel,ACHIEVING_RATE);


        //年度合计
        List<ReturnPlanDetailYearData> yearDataVoList = vo.getYearDataList();
        //月度全盘签约
        List<ReturnPlanDetailMonthData> MonthDataVoList = vo.getMonthDataList();
        if(CollectionUtils.isNotEmpty(MonthDataVoList)) {
            for(int i = 0 ; i < MonthDataVoList.size() ; i++) {
                //月度合计
                ReturnPlanDetailMonthData monthDataVo = MonthDataVoList.get(i);
                this.appendCell(row, index++,monthDataVo.getMonthEarlyReceivable(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthSign(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyActualIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyActualStoreReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyCalculateIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyCalculateStoreReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyAdjustIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyAdjustStoreReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthSignNotReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getRefundable(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyTotalIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyTotalStoreReturn(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyTotalReturnTotal(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getMonthlyTotalMonthEndReceivable(),isParentLevel,NUMERIC_FOUR);
                this.appendCell(row, index++,monthDataVo.getSignReturnRate(),isParentLevel,ACHIEVING_RATE);
                this.appendCell(row, index++,monthDataVo.getAnnualOverallReturnRate(),isParentLevel,ACHIEVING_RATE);


                int year = monthDataVo.getYear();
                int month = monthDataVo.getMonth();
                if(month == 12 || i == MonthDataVoList.size()-1){
                    List<ReturnPlanDetailYearData> yearDataVos = yearDataVoList.stream().filter(y -> y.getYear() == year).collect(Collectors.toList());
                    if(CollectionUtils.isEmpty(yearDataVos)){
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,null,isParentLevel,NUMERIC_FOUR);
                    }else {
                        ReturnPlanDetailYearData yearDataVo = yearDataVos.get(0);
                        this.appendCell(row, index++,yearDataVo.getYearEarlyReceivable(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getYearSign(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualActualIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualActualStoreReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualCalculateIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualCalculateStoreReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualAdjustIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualAdjustStoreReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getYearSignNotReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getYearEarlyRefund(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualTotalIncrementalReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualTotalStoreReturn(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualTotalReturnTotal(),isParentLevel,NUMERIC_FOUR);
                        this.appendCell(row, index++,yearDataVo.getAnnualTotalYearEndReceivable(),isParentLevel,NUMERIC_FOUR);
                    }

                }
            }
        }
        currentDataRowCursor++;
    }

    /**
     * 插入列
     * @param row 行
     * @param index 列数
     * @param value 值
     * @param isParentLevel 是否汇总行
     * @param type 样式类型
     */
    private void appendCell(XSSFRow row, int index, Object value, boolean isParentLevel, String type) {
        XSSFCell cell = row.getCell(index);
        if (cell == null) {
            cell = row.createCell(index);
        }
        if(isParentLevel){
            switch (type){
                case EQUITY_RATIO:
                    cell.setCellStyle(cellStyleA2);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue((Double.valueOf(value.toString())/100));
                    }
                    break;
                case NUMERIC_FOUR:
                    cell.setCellStyle(cellStyleA3);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue(BigDecimalUtils.divInteger(new BigDecimal(value.toString()),10000,4).doubleValue());
                    }
                    break;
                case ACHIEVING_RATE:
                    cell.setCellStyle(cellStyleA4);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue((Double.valueOf(value.toString())));
                    }
                    break;
                default:
                    cell.setCellStyle(cellStyleA1);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue((String) value);
                    }
                    break;
            }

        }else {
            switch (type){
                case EQUITY_RATIO:
                    cell.setCellStyle(cellStyleB2);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue((Double.valueOf(value.toString())/100));
                    }
                    break;
                case NUMERIC_FOUR:
                    cell.setCellStyle(cellStyleB3);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue(BigDecimalUtils.divInteger(new BigDecimal(value.toString()),10000,4).doubleValue());
                    }
                    break;
                case ACHIEVING_RATE:
                    cell.setCellStyle(cellStyleB4);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue((Double.valueOf(value.toString())));
                    }
                    break;
                default:
                    cell.setCellStyle(cellStyleB1);
                    if(value == null){
                        cell.setCellValue("");
                    }else {
                        cell.setCellValue(((String)value));
                    }
                    break;
            }
        }
    }

    /**
     * 导出
     *
     * @param outputStream
     * @throws IOException
     */
    public void write(OutputStream outputStream) throws IOException {
        workbook.write(outputStream);
    }
}
